Summary Vignette

Interaction Data Summary Statistics

library(dplyr)
library(stringr)
set.seed(44)
df <- read.csv(here::here("../Avian-Interaction-Database-Working/L1/ain_cac.csv"))
spp <- read.csv(here::here("./data/L1/species_checklists/spp_joint_cac_colsubset.csv"))

num_intxns <- nrow(df)

unique_intxns <- df %>% 
  dplyr::select(taxa1_scientific, 
                taxa2_scientific, 
                effect_tx1_on_tx2, 
                effect_tx2_on_tx1, 
                interaction) %>% 
  filter(!duplicated(.)) 



unique_pairs <- unique_intxns %>%
  mutate(
    # Labels taxa pairs by alphabetical order 
    taxa_lo = pmin(taxa1_scientific, taxa2_scientific),
    taxa_hi = pmax(taxa1_scientific, taxa2_scientific),

    # Checks whether order is swapped (non-alphabetical) 
    swapped = taxa1_scientific > taxa2_scientific,

    # normalize effects so they always mean:
    # eff_lo_on_hi = effect of taxa_lo on taxa_hi
    # eff_hi_on_lo = effect of taxa_hi on taxa_lo
    eff_lo_on_hi = if_else(swapped, effect_tx2_on_tx1, effect_tx1_on_tx2),
    eff_hi_on_lo = if_else(swapped, effect_tx1_on_tx2, effect_tx2_on_tx1)
  )  %>%
  distinct(taxa_lo, taxa_hi, interaction, eff_lo_on_hi, eff_hi_on_lo)

unique_taxa_list <- unique(c(df$taxa1_scientific, df$taxa2_scientific))
num_total_taxa <- length(unique_taxa_list)

total_cac_taxa1 <- unique(df$taxa1_scientific[df$taxa1_scientific %in% spp$scientific_name_clements2024])
total_cac_taxa2 <- unique(df$taxa2_scientific[df$taxa2_scientific %in% spp$scientific_name_clements2024])
total_cac_taxa <- unique(c(total_cac_taxa1, total_cac_taxa2))

num_non_cac_taxa <-num_total_taxa - length(total_cac_taxa)

unique_spp_list_names <- unique(spp$scientific_name_clements2024)
unique_spp1_ain_names <- unique(df$taxa1_scientific)

#Removing hybrids, genera and unidentified
unique_spp_sbp_list <- unique_taxa_list[!str_detect(unique_taxa_list, regex("sp\\.|unid\\.|_x_", ignore_case = TRUE))]
unique_spp_list <- unique(str_replace(unique_spp_sbp_list, "^([A-Za-z]+\\s+[A-Za-z]+).*$", "\\1"))
unique_gen_list <- unique(str_replace(unique_spp_list, "^([A-Za-z]+).*$", "\\1"))

na_spp_list <- unique_spp_list[unique_spp_list %in% spp$scientific_name_clements2024]

na_gen_list <- unique(str_replace(na_spp_list, "^([A-Za-z]+).*$", "\\1"))
  • Number of documented pairwise interactions: 25958

  • Number of unique pairwise interactions: 18427

  • Number of focal taxa: 727

  • Number of additional non-focal taxa: 1395

  • Number of taxa (total): 2122

  • Number of North American species: 695

  • Number of additional species: 934

  • Number of species (total): 1629

  • Percent of world’s bird spp (out of 11,1145 spp): 14.62

  • Number of North American Genera:321

  • Number of additional genera: 317

  • Number of total genera: 638

  • Total number of interaction types: 23

Species list summary

  • Total number of species in the North American Avian Interaction Species List: 777
unique_intxns %>% group_by(interaction) %>% summarize(n=n()) %>% arrange(-n)
# A tibble: 23 × 2
   interaction                     n
   <chr>                       <int>
 1 predation                    5388
 2 competition                  3122
 3 co-occur                     2189
 4 brood parasitism             1509
 5 facilitation                 1447
 6 commensalism                 1091
 7 mobbing                       939
 8 communal nesting              904
 9 communal roosting             710
10 facilitation-mixed flocking   699
# ℹ 13 more rows

Interaction Data Exploratory Figures

Source _figure_processing.R which contains the data processing and plotting functions. See 5.5_figure_processing_vignette.qmd for further explanation of the data processing and plot functions!

source(here::here("../Avian-Interaction-Database/R/L2/_figure_processing.R"))

Interaction Distribution Figure

#Defining the position of the brackets in the figure
bracket_data <- type_summ_total %>%
  group_by(category) %>% 
  summarize( 
    y_min = min(as.numeric(interaction)), #Vertical portion of brackets
    y_max = max(as.numeric(interaction)),
    n_types = n(),
    total_n = sum(total),  
    total_unique = sum(unique)
  ) %>%
  filter(n_types > 1) %>%  #No brackets are needed for categories with only 1 type!
  mutate(
    y_min = y_min - 0.4,  #Shortened vertical extent
    y_max = y_max + 0.4,  
    x_pos = max(type_summ$total) * 0.5,  #Position brackets to the right
    x_end = max(type_summ$total) * 0.6,  #End of bracket
    y_mid = (y_min + y_max) / 2,      #Midpoint for category label
    category_label = paste0(category, ": ", total_n, " (", total_unique, ")")  
  ) %>%
  #Using color from first interaction for each category
  left_join(
    type_summ_total %>%
      group_by(category) %>%
      slice(1) %>%
      select(category, bracket_color = color),
    by = "category"
  )

ggplot(type_summ_total, aes(x = interaction, y = total, fill = interaction)) +
  theme_light() +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = setNames(interaction_categories$color,
                                      interaction_categories$interaction)) +
  geom_text(aes(label = paste0(total, " (", unique, ")")), hjust = -0.2, size = 4.25) +
  #Bracket: lower bar
  geom_segment(data = bracket_data,
               aes(x = y_min, xend = y_min, 
                   y = x_pos, yend = x_end, color = bracket_color),
               inherit.aes = FALSE, linewidth = 1.5) +
  #Bracket: upper bar
  geom_segment(data = bracket_data,
               aes(x = y_max, xend = y_max, 
                   y = x_pos, yend = x_end, color = bracket_color),
               inherit.aes = FALSE, linewidth = 1.5) +
  #Bracket: side bar
  geom_segment(data = bracket_data,
               aes(x = y_min, xend = y_max, 
                   y = x_end, yend = x_end, color = bracket_color),
               inherit.aes = FALSE, linewidth = 1.5) +
  scale_color_identity() +  
  #Category labels
  geom_text(data = bracket_data,
            aes(x = y_mid, y = x_end + 80, 
                label = category_label),  #Use the new label
            inherit.aes = FALSE, size = 4.25, hjust = 0) +
  theme(axis.text.x = element_text(angle = 0, size = 14),  
        axis.text.y = element_text(size = 14),             
        axis.title = element_text(size = 16),              
        plot.title = element_text(size = 18),              
        legend.position = "none") +
  xlab("") +
  ylab("") +
  coord_flip() +
  scale_y_continuous(expand = expansion(mult = c(0.05, 0.25)))

Interaction Phylogeny Figure

phyloplot_species <- plot_phylo_combined(
  tree = NA_tree,
  data = inter_NA_working,
  value_col = "n_int",
  label_offset = 8,
  label_size = 4.5,
  tip_size = 2,
  min_species = 25,
  legend_title = "Number of interactions"
)
phyloplot_species

Interaction Network Figure

create_network(inter_NA_int, "Baeolophus inornatus", curve_edges = T, show_labels = F, cats = T)

create_combined_network(inter_NA_int, c("Baeolophus inornatus", "Dryobates nuttallii", "Glaucidium gnoma"), curve_edges = T, cats = F)

create_combined_network(inter_NA_int, c("Baeolophus inornatus", "Dryobates nuttallii", "Glaucidium gnoma"), curve_edges = T, cats = T, legend_text_size = 35, legend_line_size = 5)